﻿using HTB.DevFx.Utils;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Maple.Weixin.MP.Entities.CustomerService
{
    /// <summary>
    /// 表示多客服账号。
    /// </summary>
    public class DkfAccount
    {
        public string kf_account { get; set; }
        public string kf_nick { get; set; }
        public string kf_id { get; set; }
        public string kf_headimg { get; set; }
        public string kf_password { get; set; }


        /// <summary>
        /// 尝试对给定的字符串进行客服账号的解析。
        /// </summary>
        /// <param name="account">给定的客服账号。</param>
        /// <param name="prefix">账号前缀。</param>
        /// <param name="wxAccount">账号所属的微信号。</param>
        /// <returns>是否解析成功。</returns>
        public static bool TryParse(string account, out string prefix, out string wxAccount) {
            prefix = "";
            wxAccount = "";
            int index = account.IndexOf('@');
            if (index == -1)
                return false;

            prefix = account.Substring(0, index);
            wxAccount = account.Substring(index + 1);
            return true;
        }

        public string ToJson()
        {
            var entity = new
            {
                kf_account= this.kf_account,
                nickname = this.kf_nick,
                password = this.kf_password
            };

            return JsonHelper.ToJson(entity, true);
        }
    }
}
